home *** CD-ROM | disk | FTP | other *** search
- #include "all.h"
- #include <math.h>
- #include <time.h>
-
- #define true (!false)
- #define false 0
- #define dbg if (gle_debug>0)
- extern int done_open;
- extern int gle_debug;
- extern int trace_on;
- extern int netxt;
- extern int this_line;
- long *(*gpcode)[]; /* gpcode is a pointer to an array of poiter to long */
- long (*gplen)[]; /* gpcode is a pointer to an array of long */
- int ngpcode=0;
- extern int ngtxt;
- extern char *(*gtxt)[];
- int ngerror;
- extern int last_line;
- char *line(int i);
- int pass_checkmode(void);
- int expand_pcode(int i, int *j);
- char *dr_nextline(int *srclin);
- int dr_init(void);
- int getch(void);
- int fner(char *s);
- int abort_flag;
- static char inbuff[300];
- int var_def(char *s, double x);
- /*---------------------------------------------------------------------------*/
- gle_redraw()
- {
- static char xinbuff[200];
- char source[20];
- static char *tk[500];
- static char tkbuff[500];
- int ntok,f;
- long time1,time2;
- static long pcode[500];
- double oval;
- int maxpcode=0;
- int plen,cp,otyp,ii,i,j,al,endp;
- FILE *fptr;
- char space_str[] = " ";
- char fname[80],*s;
- ngpcode = 0;
- expand_pcode(ngtxt,&maxpcode);
-
- token_space();
- /* Now compile the file into pcode */
- for (i=0;i<500;i++) tk[i] = space_str;
- abort_flag = false;
- ngerror = 0;
- netxt = 0;
- last_line = 0;
- fner("CGLE V3.3b, Compiling...");
-
- mark_clear();
- sub_clear();
- for_init();
- f_init();
- dr_init();
- var_def("PI",3.14159265);
- done_open = false;
- for (;(s = dr_nextline(&i)) != NULL;) {
- strcpy(xinbuff,s);
- al = strlen(xinbuff);
- if (xinbuff[al-1]=='&') {
- xinbuff[al-1] = 0;
- strcat(xinbuff, dr_nextline(&i));
- }
- if (xinbuff[0]==26) xinbuff[0] = 0;
- strcpy(inbuff,xinbuff);
- this_line = i;
- if (trace_on) gprint("Source | %s \n",xinbuff);
- token(xinbuff,&tk,&ntok,tkbuff);
- plen = 0;
- passt(ngpcode+1,inbuff,&tk,&ntok,pcode,&plen);
- /*
- for (ii=0;ii<plen;ii++) {
- printf("%x ",pcode[ii]);
- }
- printf("\n");
- */
- if (ngpcode > maxpcode) expand_pcode(ngpcode*2,&maxpcode);
- (*gpcode)[++ngpcode] = myallocz(plen*4);
- (*gplen)[ngpcode] = plen;
- memcpy((*gpcode)[ngpcode],&pcode,plen*4);
- if (abort_key()) goto do_abort;
- }
- pass_checkmode();
-
- time(&time2);
- fner("CGLE V3.3b, Running...");
- if (ngerror>0) {
- gprint("Abort (Y/N) [Y] \n");
- if (tolower(text_inkey())!='n') return;
- }
- for (i=1;i<=ngpcode;i++) {
- if (abort_key()) goto do_abort;
- this_line = i;
- if (trace_on) gprint("Trace |%s\n",line(i));
- dbg gprint("Call do_pcode[%d] \n",i);
- /* printf("Pcode pointer %p %d \n",(*gpcode)[i],i);*/
- do_pcode(&i,(*gpcode)[i],(*gplen)[i],&endp);
- }
- do_abort:
- g_close();
-
- for (i=1;i<=ngpcode;i++) {
- this_line = i;
- if ( (*gpcode)[i] != NULL) myfrees( (*gpcode)[i] ,"gpcode");
- }
-
- }
- /*--------------------------------------------------------------------------*/
- glezzz()
- {
- printf("~~~~~~~~~~~~~~~~~~Pcode pointer %p 2 \n",(*gpcode)[2]);
- }
- gle_include(char *s)
- {
- gprint("include file (not implemented ) {%s} \n",s);
- }
- /*--------------------------------------------------------------------------*/
- extern char gleroot[];
- char *gle_top()
- {
- char *s;
- #ifdef unix
- return gleroot;
- #endif
- #ifdef __TURBOC__
- return gleroot;
- #else
- return "cgle_top:";
- #endif
- }
- char *gledir(char *s);
- char *bgidir()
- {
- #ifdef __TURBOC__
- char *s;
- s = getenv("GLE_BGI");
- if (s==NULL) {
- s = gledir("");
- }
- return s;
- #endif
- }
-
- char *fontdir(char *fname)
- {
- static char fbuff[80];
- #ifdef __TURBOC__
- strcpy(fbuff,gle_top());
- strcat(fbuff,"font\\");
- #else
- strcpy(fbuff,"cgle_top:");
- #endif
- #ifdef unix
- strcpy(fbuff,gle_top());
- strcat(fbuff,"font/");
- #endif
- strcat(fbuff,fname);
- return &fbuff[0];
- }
- char *gledir(char *fname)
- {
- static char fbuff[80];
- #ifdef __TURBOC__
- strcpy(fbuff,gle_top());
- strcat(fbuff,"exe\\");
- #else
- strcpy(fbuff,"cgle_top:");
- #endif
- #ifdef unix
- strcpy(fbuff,gle_top());
- #endif
- strcat(fbuff,fname);
- return &fbuff[0];
- }
- static int dri;
- static ninc=0;
- static FILE *incptr[10];
- include_file(char *fname)
- {
- incptr[++ninc] = fopen(fname,"r");
- if (incptr[ninc]==NULL) {
- gprint("Unable to open input file {%s} \n",fname);
- perror("Reason"); ninc--;
- }
- }
- dr_init()
- {
- dri = 1;
- }
- char *dr_nextline(int *srclin)
- {
- int i;
- try_again:;
- if (ninc==0) {
- if (dri>ngtxt) return NULL;
- *srclin = dri;
- return (*gtxt)[dri++];
- } else {
- if (feof(incptr[ninc])) goto close_file;
- if (fgets(inbuff,190,incptr[ninc])==NULL) goto close_file;
- i = strlen(inbuff);
- if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
- return inbuff;
- }
- close_file:
- fclose(incptr[ninc--]);
- goto try_again;
- }
- expand_pcode(int ngtxt,int *maxpcode)
- {
- long *a,*b;
- a = myallocz((ngtxt+10)*4);
- b = myallocz((ngtxt+10)*4);
- if (gpcode!=0) {
- memcpy(a,gpcode,(*maxpcode + 4)*4);
- memcpy(b,gplen,(*maxpcode + 4)*4);
- myfrees(gpcode,"gpcode2");
- myfrees(gplen,"gplen");
- }
- gpcode = (long *(*)[]) a;
- gplen = (long (*)[]) b;
- *maxpcode = ngtxt+1;
- }
- run_bigfile(char *fname)
- {
- FILE *fptr;
- char inbuff[200],s[200];
- char *tk[300];
- char tkbuff[300];
- long pcode[300];
- int plen,ntok,i,endp;
-
- fptr = fopen(fname,"r");
- if (fptr==NULL) {
- gprint("Unable to open bigfile {%s} \n",fname);
- perror("Reason");
- return;
- }
- for (;!feof(fptr);) {
- if (fgets(inbuff,190,fptr)!=NULL) {
- strcpy(s,inbuff);
- i = strlen(inbuff);
- if (inbuff[i-1]=='\n') inbuff[i-1] = 0;
- if (trace_on) gprint("Source | %s \n",inbuff);
- token(inbuff,&tk,&ntok,tkbuff);
- plen = 0;
- passt(ngpcode+1,s,&tk,&ntok,pcode,&plen);
- do_pcode(&i,pcode,plen,&endp);
- }
- }
- fclose(fptr);
- }
-